// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from "axios";
import Button from 'ant-design-vue/lib/button';
import Table from 'ant-design-vue/lib/table';
import Menu from 'ant-design-vue/lib/menu';
import Input from 'ant-design-vue/lib/input';
import Spin from 'ant-design-vue/lib/spin';
import Message from 'ant-design-vue/lib/message';
import Progress from 'ant-design-vue/lib/progress';
import Popconfirm from 'ant-design-vue/lib/popconfirm';
import Drawer from 'ant-design-vue/lib/drawer';
import Select  from 'ant-design-vue/lib/select';
import Form from 'ant-design-vue/lib/form';
import InputNumber from 'ant-design-vue/lib/input-number';
import DatePick from 'ant-design-vue/lib/date-picker';
import Upload from 'ant-design-vue/lib/upload';

import Icon from 'ant-design-vue/lib/icon';
import Switch from 'ant-design-vue/lib/switch';



import 'ant-design-vue/dist/antd.css';

import {GLOBAL_} from "./Const/config.js";

import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
  
Vue.use(VueQuillEditor)

Vue.component(Button.name, Button);
Vue.use(Menu);
Vue.use(Table);
Vue.use(Input);
Vue.use(InputNumber);
Vue.use(Icon);
Vue.use(Switch);
Vue.use(Spin);
Vue.use(Progress);
Vue.use(Popconfirm);
Vue.use(Drawer);
Vue.use(Select);
Vue.use(Form);
Vue.use(DatePick);
Vue.use(Upload);

Message.config({
  top: `200px`
});

Vue.prototype.$axios = axios;
Vue.prototype.$form = Form;
Vue.prototype.GLOBAL_ = GLOBAL_;
Vue.prototype.$message = Message;

Vue.config.productionTip = false

router.beforeEach((to,from,next)=>{
    if (!(to.path === '/login')) {
      if (window.localStorage.getItem('token')) {
        next()
      } else {
        
        next('/login')
      }
    } else {
      next()  // 确保一定要有next()被调用
    }
})




axios.interceptors.request.use(
  config=> {
    let token = window.localStorage.getItem("token");
    if(token!=null){
      config.headers.token = token;
    }
    return config;
 })

  
// Vue.http.interceptors.push((request, next) => {
//   request.headers.set('token', localStorage.getItem("token"));
//   next((response) => {
//     return response
//   })
// })


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})


